//Objective
_curObj = _this select 0;
//_towerArray = _this select 1;
//_complete = str(_curobj+"complete");
_tower1Check = _curobj+"_t1";
_tower2Check = _curobj+"_t2";
_tower3Check = _curobj+"_t3";
_towerArray = [_tower1Check,_tower2Check,_tower3Check];
_randomTower = _towerArray select floor(random(count _towerArray));
randomTower = _randomTower;

//hint format["Current tower array == %1",_curTowerArray];

	radioTower = createvehicle ["Land_Communication_F", (position player)];
	radioTower setdammage 0;
	radioTower allowdamage false;
	//radioTower setposATL (getMarkerPos randomTower);
	radioTower setposATL [getMarkerPos randomTower select 0,(getMarkerPos randomTower select 1)+2,-10];
//	player setposATL (getMarkerPos randomTower);

	device_closed setposATL [getMarkerPos randomTower select 0, getMarkerPos randomTower select 1,0];



//Area Marker
	_aoMarker = createMarker ["AO", position player];
	"AO" setMarkerSize [300, 300];
	"AO" setMarkerPos getMarkerPos _curobj;
	"AO" setMarkerShape "ELLIPSE";
	"AO" setMarkerColor "ColorRed";
	"AO" setMarkerAlpha 0.5; 

//Detection triggers
ao_Edetector = createTrigger ["EmptyDetector", (getMarkerPos "AO")];
	ao_Edetector setTriggerActivation ["EAST","PRESENT", true];
	ao_Edetector setTriggerArea [300, 300, 0, true];
	ao_Edetector setTriggerTimeout [2, 2, 2, true];
	
ao_Wdetector = createTrigger ["EmptyDetector", (getMarkerPos "AO")];
	ao_Wdetector setTriggerActivation ["WEST","PRESENT", false];
	ao_Wdetector setTriggerArea [150, 150, 0, true];
	ao_Wdetector setTriggerTimeout [2, 2, 2, true];
//	ao_Wdetector setTriggerStatements ["alive radioTower", "nul = [_curobj,2,true,false,5000,275,true,250,300,1,50,true,true,true,true] execVM ""AIM\heliParadrop.sqf"";", ""];

/*
aa3=createTrigger["EmptyDetector",(getMarkerPos de11];
aa3 setTriggerArea[500,500,0,false];
aa3 setTriggerActivation["ANY","PRESENT",true];
aa3 setTriggerStatements["this", "{_x setDamage 1} foreach thisList;", ""];
hint "triggers set"

while {true} do {
	_damagecheck = getdammage radioTower;
	hint format["radioTower damage = %1",_damagecheck];
	sleep 10;
};
*/
//Enemy Loadouts------------------------------------------------------------------------
#include "enemyLoadout.sqf";
	
//Populate Enemy------------------------------------------------------------------------
	//	nul = [_curobj] execVM "AIM\militarize.sqf";
	//	nul = [_curobj] execVM "AIM\fillHouse.sqf";
	//	nul = [_curobj] execVM "AIM\heliParadrop.sqf";

nul = 
[
	_curobj, 				//target
	2,						//side [0=civ 1=B 2=O 3=I]
	150,					//radius
	[true,false],			//spawn men [land/water]
	[true,false,false],		//spawn vehicles [land/water/air]			
	false,					//mobile outside of radius
	[14,20],				//men ratio [atLeast + randomX]
	[0,0],					//vehicle ratio [atLeast + randomX]
	//skills [aimingAccuracy, aimingShake, aimingSpeed, spotDistance, spotTime, courage, commanding, general, endurance, reloadSpeed] 	
		[0.2,0.4,0.1,0.65,0.9,0.75,0.1,0.5,0.8,0.3]
		, 		
	nil,					//group [group name or nil]	
	//custom init
		_enemyEasyLoadout	
	 ,	
	1						//number (if you want to delete units this script creates, you'll need ID number for them)
] execVM "EW_Server_Side\Blank SS mission files\AIM\militarize.sqf";
nul = 
[
	_curobj, 				//target
	2,						//side [0=civ 1=B 2=O 3=I]
	150,					//radius
	[true,false],			//spawn men [land/water]
	[true,false,false],		//spawn vehicles [land/water/air]			
	false,					//mobile outside of radius
	[8,10],				//men ratio [atLeast + randomX]
	[0,0],					//vehicle ratio [atLeast + randomX]
	//skills [aimingAccuracy, aimingShake, aimingSpeed, spotDistance, spotTime, courage, commanding, general, endurance, reloadSpeed] 	
		[0.2,0.4,0.1,0.65,0.9,0.75,0.1,0.5,0.8,0.3]
		, 		
	nil,					//group [group name or nil]	
	//custom init
		_enemyMediumLoadout	
	 ,	
	1						//number (if you want to delete units this script creates, you'll need ID number for them)
] execVM "EW_Server_Side\Blank SS mission files\AIM\militarize.sqf";
nul = 
[
	_curobj, 				//target
	2,						//side [0=civ 1=B 2=O 3=I]
	150,					//radius
	[true,false],			//spawn men [land/water]
	[true,false,false],		//spawn vehicles [land/water/air]			
	false,					//mobile outside of radius
	[2,3],				//men ratio [atLeast + randomX]
	[0,0],					//vehicle ratio [atLeast + randomX]
	//skills [aimingAccuracy, aimingShake, aimingSpeed, spotDistance, spotTime, courage, commanding, general, endurance, reloadSpeed] 	
		[0.2,0.4,0.1,0.65,0.9,0.75,0.1,0.5,0.8,0.3]
		, 		
	nil,					//group [group name or nil]	
	//custom init
		_enemyHardLoadout	
	 ,	
	1						//number (if you want to delete units this script creates, you'll need ID number for them)
] execVM "EW_Server_Side\Blank SS mission files\AIM\militarize.sqf";
nul = 
[
	_curobj, 				//target
	0,						//side [0=civ 1=B 2=O 3=I]
	150,					//radius
	[true,false],			//spawn men [land/water]
	[true,false,false],		//spawn vehicles [land/water/air]			
	false,					//mobile outside of radius
	[3,10],				//men ratio [atLeast + randomX]
	[0,0],					//vehicle ratio [atLeast + randomX]
	//skills [aimingAccuracy, aimingShake, aimingSpeed, spotDistance, spotTime, courage, commanding, general, endurance, reloadSpeed] 	
		[0.2,0.4,0.1,0.65,0.9,0.75,0.1,0.5,0.8,0.3]
		, 		
	nil,					//group [group name or nil]	
	//custom init
	nil,	
	1						//number (if you want to delete units this script creates, you'll need ID number for them)
] execVM "EW_Server_Side\Blank SS mission files\AIM\militarize.sqf";

	



//Tower Managment loop-----------------------------------------------------------------------
while {alive radioTower} do {
//	hint "objGenerator has started the loop";
//	_distance = player distance radioTower;
//	hint "EW_debug_objgeneratorRunning";
//	if (_distance < 250) exitwith {
//		radioTower allowdamage true;
_towerprox = player distance radioTower;
	if (_towerprox < 500) exitwith {
			_radioTowerMarker = createMarker ["radioTowerMarker", position player];
			"radioTowerMarker" setMarkerText "Radio Tower";
			"radioTowerMarker" setMarkerSize [0.5, 0.5];
			"radioTowerMarker" setMarkerPos getPos radioTower;
			"radioTowerMarker" setMarkerShape "ICON";
			"radioTowerMarker" setMarkerType "hd_destroy";
			"radioTowerMarker" setMarkerColor "ColorRed";
//		"objtower1marker" setMarkerAlphaLocal 1 ;
//		"objtower1marker" setMarkerPos getPos radioTower;
//		hint "EW_debug_proximityTower";
	};
	sleep 5;
};
//server decides-----------------------------------------------------------------------
	for [{_loop=0}, {_loop<1}, {_loop=_loop}] do {
		if (!alive device_open) then {
			if ("Man" countType list ao_Edetector <= 6) then {
				if ("Tank" countType list ao_Edetector  <= 1) then {
					if("Car" countType list ao_Edetector <= 1) exitwith {
						_loop=1;
					};
				};
			};
		};
		Sleep 4;
	};
	[["EW_debug_enemySurrendered"],"BIS_fnc_guiMessage",nil,true] spawn BIS_fnc_MP;
	objArray = objArray - [_curObj];
	publicVariable str(objArray);
//	nul = [_curobj,2,true,false,5000,275,true,250,300,1,50,true,true,true,true] execVM "AIM\heliParadrop.sqf";

//Cleanup on all clients---------------------------------------------------------------------
	{_handle = [_x] execVM "EW_Server_Side\Blank SS mission files\AIM\surrender.sqf"} forEach (list ao_Edetector);
	{_x addscore 10} forEach (list ao_Wdetector);
	deleteMarker "radioTowerMarker";
	deleteMarker "AO";
	deleteVehicle ao_Edetector;
	deleteVehicle ao_Wdetector;
	device_open setpos getpos shadow;
	device_open setdammage 0;
	device_open allowdammage false;
	deletevehicle radioTower;
//	hint "EW_debug_objGeneratorComplete";

//Next AO-----------------------------------------------------------------------------------
if (count objArray == 0) then { 
	_ghint = "EW_debug_objGenerator_ScriptComplete";
	GlobalHint = _ghint;
	publicVariable "GlobalHint";
}else {
	_randomObj = objArray select floor(random(count objArray));
	[_randomObj] execVM "EW_Server_Side\Blank SS mission files\objGenerator.sqf";
};